/*
 * @Author: your name
 * @Date: 2024-06-05 13:33:32
 * @LastEditTime: 2024-06-05 13:41:52
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\738.单调递增的数字.cpp
 */
/*
 * @lc app=leetcode.cn id=738 lang=cpp
 *
 * [738] 单调递增的数字
 */

// @lc code=start
class Solution {
public:
    int monotoneIncreasingDigits(int n) {
        // 转化为字符串
        string s = to_string(n);
        int index = s.size();
        for(int i = s.size()-1; i > 0; i--){
            if(s[i-1] > s[i]){
                index = i;
                
                s[i-1]--;
            }
        }
        for(int i = index; i<s.size();i++){
            s[i] = '9';
        }
        return stoi(s);
    }
};
// @lc code=end

